package com.fudan.framework.entity;

import java.util.HashMap;
import java.util.Map;

/**
 * AJAX返回值封装，由状态码，传递消息，传递数据组成
 * @author Xuxinxing
 *
 */
public class ResponseMsg {

	private Integer code;
	private String msg;
	private Map<String, Object> values;
	
	private ResponseMsg() {}
	private ResponseMsg(Integer code) {
		this.code = code;
	}
	private ResponseMsg(Integer code,String msg) {
		this.code = code;
		this.msg = msg;
	}
	public static ResponseMsg build() {
		return new ResponseMsg(0);
	}
	public static ResponseMsg build(Integer code) {
		return new ResponseMsg(code);
	}
	public static ResponseMsg build(Integer code,String msg) {
		return new ResponseMsg(code,msg);
	}
	public static ResponseMsg build(Integer code,String msg,Object value) {
		ResponseMsg rm = new ResponseMsg(code,msg);
		rm.put("data", value);
		return rm;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Map<String, Object> getValues() {
		return values;
	}

	public ResponseMsg put(String key, Object val) {
		if (values == null) {
			synchronized (this) {
				if (values == null) {
					values = new HashMap<>();
				}
			}
		}
		values.put(key, val);
		return this;
	}
	public ResponseMsg putData(Object val) {
		if (values == null) {
			synchronized (this) {
				if (values == null) {
					values = new HashMap<>();
				}
			}
		}
		values.put("data", val);
		return this;
	}

}
